package com.levi.distributedjob.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * 测试非分布式的任务   @Scheduled
 */
@Component
@Slf4j
public class ScheduledJob {

    @Autowired
    private AsyncProcess asyncProcess;

    @Scheduled(fixedRate = 3000)
    /**
     * cron表达式
     * 秒 分 小时 日 月 星期
     * 官网    https://cron.qqe2.com/
     */

    @Scheduled(cron = "* * * * * ?")
    public void process1() throws InterruptedException {

        log.info("process1  start...");
        Thread.sleep(5000);
        log.info("process1  end...");
    }



    @Scheduled(fixedRate = 3000)
    public void process2() throws InterruptedException {
        log.info("process2  start...");
        Thread.sleep(5000);
        log.info("process2  end...");
    }


    @Scheduled(fixedRate = 3000)
    public void asyncProcess() throws InterruptedException {
        asyncProcess.asyncProcess();
    }

}
